clear all
version 16.1
net install grstyle.pkg
net install esttab.pkg
net install coefplot.pkg

grstyle init
grstyle set plain
* colorpalette #259797 #db4437
graph set window fontface "Times New Roman"

log using HorowitzKahnAutomationBiasReplication.log, replace

insheet using "reshaped_automationBias_dataComplete_withIndices.csv", comma

* Corrections from data being in R *
gen level2=.
replace level2=0 if level=="level3_test1" | level=="level3_test2" | level=="level3_test3" | level=="level3_test4" | level=="level3_test5"
replace level2=1 if level=="level4_test1" | level=="level4_test2" | level=="level4_test3" | level=="level4_test4" | level=="level4_test5"
label var level2 "Difficulty: 0 if Level3, 1 if Level 4"
rename level level_text
rename level2 level

replace confirmation_correct="." if confirmation_correct=="NA"
replace qpolitical="." if qpolitical=="NA"
replace qpolitical="." if qpolitical=="Don’t know"
replace switched_ai="." if switched_ai=="NA"
replace switched_human="." if switched_human=="NA"
* replace ideo10 ="0" if ideo10=="0 - Left"
* replace ideo10 ="10" if ideo10=="10 - Right"
* replace ideo10 ="." if ideo10=="Don't know"
* replace ideo10="." if ideo10=="NA"
replace overall_aibeliefs2="." if overall_aibeliefs2=="NA"
replace normalized_overall_aibeliefs2="." if normalized_overall_aibeliefs2=="NA"

* Education *
gen educ="."
replace educ="0" if educationq=="I have no formal qualifications"
replace educ="1" if educationq=="I have some qualifications but did not attend university"
replace educ="2" if educationq=="I attended university but did not graduate"
replace educ="3" if educationq=="I attended university and achieved a Bachelor’s degree (e.g. BA, BSc, etc.)"
replace educ="3" if educationq=="I attended university and achieved a Bachelor's degree (for example BA, BSc, etc.)"
replace educ="4" if educationq=="I attended graduate school but did not graduate"
replace educ="4" if educationq=="I attended university and began a graduate programme, but did not complete that programme"
replace educ="5" if educationq=="I attended graduate school and went to achieve a higher degree (e.g. MA, MSc, PhD, Mphil, etc.)"
replace educ="5" if educationq=="I attended university and went on to achieve a higher degree (for example MA, MSc, PhD, Mphil, etc.)"

replace overall_aisentiment_index="." if overall_aisentiment_index=="NA"

destring, replace

* replace qpolitical=ideo10 if ideo10>=0 & ideo10<=10 & qpolitical==.
replace qpolitical=. if qpolitical==999

gen switch=0
replace switch=1 if switched_ai==1 | switched_human==1
label var switch "Respondent Switched In Response To Treatment"

gen quiz=0
replace quiz=1 if quizq1_score==1 | quizq2_score==1
replace quiz=2 if quizq1_score==1 & quizq2_score==1
label var quiz "AI Quiz 1 = one right, 2 = both right"

gen female=0
replace female=1 if sex=="Female"

gen treatment_control=0
replace treatment_control=1 if treatment_human==0 & treatment_ai==0

egen newid = group(caseid)

gen australia=0
replace australia=1 if country=="Australia"
gen china=0
replace china=1 if country=="China"
gen france=0
replace france=1 if country=="France"
gen japan=0
replace japan=1 if country=="Japan"
gen skorea=0
replace skorea=1 if country=="Republic of Korea"
gen russia=0
replace russia=1 if country=="Russian Federation"
gen sweden=0
replace sweden=1 if country=="Sweden"
gen usa=0
replace usa=1 if country=="United States"
gen uk=0
replace uk=1 if country=="United Kingdom"

gen countryid=0
replace countryid=1 if country=="Australia"
replace countryid=2 if country=="China"
replace countryid=3 if country=="France"
replace countryid=4 if country=="Japan"
replace countryid=5 if country=="Republic of Korea"
replace countryid=6 if country=="Russian Federation"
replace countryid=7 if country=="Sweden"
replace countryid=8 if country=="United States"
replace countryid=9 if country=="United Kingdom"

label var overallai_familiarity "AI Familiarity"
label var overall_aisentiment_index "Overall AI Sentiment Index"
label var level "Level of Difficulty"
label var total_practice_correct "Practice Round Accuracy"
label var age "Age"
label var female "Gender"
label var educ "Level of Education"
label var treatment_high "Treatment Condition: High Confidence"
label var ai_background_index3 "AI Background Index"
label var russia "Russia"
label var china "China"
label var sweden "Sweden"
label var uk "United Kingdom"
label var usa "United States"
label var france "France"
label var japan "Japan"
label var australia "Australia"
label var skorea "South Korea"

gen switchright=.
replace switchright=1 if identification_correct==0 & confirmation_correct ==1
replace switchright=0 if identification_correct==0 & confirmation_correct ==0
replace switchright=0 if identification_correct==1 & confirmation_correct ==0
replace switchright=0 if identification_correct==1 & confirmation_correct ==1
gen switchwrong=.
replace switchwrong=1 if identification_correct==1 & confirmation_correct == 0
replace switchwrong=0 if identification_correct==1 & confirmation_correct == 1
replace switchwrong=0 if identification_correct==0 & confirmation_correct == 1
replace switchwrong=0 if identification_correct==0 & confirmation_correct == 0

gen aifamiliaritysquared=overallai_familiarity*overallai_familiarity
label var aifamiliaritysquared "AI Familiarity Squared"

label var normalized_overall_aibeliefs2 "Normalized AI Sentiment"

gen aibackground=(overallai_experience2*(.4))+(overallai_familiarity*(.4))+(overallai_knowledge2*(.2))
gen aibackgroundsquared=aibackground*aibackground
label var aibackgroundsquared "AI Background Index Squared"
label var aibackground "AI Background Index"
label var treatment_ai "Treatment Condition: AI"
label var qpolitical "Political Ideology"
gen aiexperiencesquared=overallai_experience2*overallai_experience2
label var aiexperiencesquared "AI Experience Squared"
gen overallai_knowledge2squared= overallai_knowledge2*overallai_knowledge2
label var overallai_knowledge2squared "AI Knowledge Squared"
label var overallai_knowledge2 "AI Knowledge"
gen overallai_experience2squared=overallai_experience2*overallai_experience2
label var overallai_experience2squared "AI Experience Squared"
label var overallai_experience2 "AI Experience"

* Table 2

* Overall Binary
eststo m1: regress switch level total_practice_correct age female educ treatment_ai treatment_high russia china uk australia japan skorea france sweden, cluster(caseid)

* Overall AI Condition
eststo m2: regress switch level total_practice_correct age female educ treatment_highconfidence russia china uk australia japan skorea france sweden if treatment_control==0 & treatment_ai==1, cluster(caseid)

* Overall Human Condition
eststo m3: regress switch level total_practice_correct age female educ treatment_highconfidence russia china uk australia japan skorea france sweden if treatment_control==0 & treatment_human==1, cluster(caseid)

*AI Familiarity Squared
eststo m4: logit switch qpolitical level total_practice_correct age female educ treatment_highconfidence overallai_familiarity aifamiliaritysquared normalized_overall_aibeliefs2 [pweight=weight] if treatment_ai==1, cluster(caseid)

* AI Knowledge Squared
eststo m5: logit switch qpolitical level total_practice_correct age female educ treatment_high overallai_knowledge2 overallai_knowledge2squared normalized_overall_aibeliefs2 [pweight=weight] if treatment_ai==1, cluster(caseid)

* AI Experience Squared
eststo m6: logit switch qpolitical level total_practice_correct age female educ treatment_high overallai_experience2 overallai_experience2squared normalized_overall_aibeliefs2 [pweight=weight] if treatment_ai==1, cluster(caseid)

*AI Background Squared
eststo m7: logit switch qpolitical level total_practice_correct age female educ treatment_highconfidence aibackground aibackgroundsquared normalized_overall_aibeliefs2 [pweight=weight] if treatment_ai==1, cluster(caseid)

esttab m1 m2 m3 m4 m5 m6 m7 using Table2.tex, replace f t(3) scalars("ll Log Likelihood" F) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 r2 b(3) star(* 0.10 ** 0.05 *** 0.01) nobaselevels order(qpolitical level total_practice_correct age female educ treatment_ai treatment_highconfidence overallai_familiarity aifamiliaritysquared overallai_knowledge2 overallai_knowledge2squared overallai_experience2 overallai_experience2squared aibackground aibackgroundsquared normalized_overall_aibeliefs2) drop(russia china uk australia japan skorea france sweden) mtitles("\shortstack{Overall\\Binary\\b/SE}" "\shortstack{AI Condition\\Binary\\b/SE}" "\shortstack{Human Condition\\Binary\\b/SE}" "\shortstack{Switching in AI Condition\\AI Familiarity Model\\b/SE}" "\shortstack{Switching in AI Condition\\AI Knowledge Model\\b/SE}" "\shortstack{Switching in AI Condition\\AI Experience Model\\b/SE}" "\shortstack{Switching in AI Condition\\AI Background Model\\b/SE}") eqlabel(none)

esttab m1 m2 m3 m4 m5 m6 m7 using Table2.rtf, replace t(3) scalars("ll Log Likelihood" F) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 r2 b(3) star(* 0.10 ** 0.05 *** 0.01) nobaselevels order(qpolitical level total_practice_correct age female educ treatment_ai treatment_highconfidence overallai_familiarity aifamiliaritysquared overallai_knowledge2 overallai_knowledge2squared overallai_experience2 overallai_experience2squared aibackground aibackgroundsquared normalized_overall_aibeliefs2) drop(russia china uk australia japan skorea france sweden) mtitles("\shortstack{Overall\\Binary\\b/SE}" "\shortstack{AI Condition\\Binary\\b/SE}" "\shortstack{Human Condition\\Binary\\b/SE}" "\shortstack{Switching in AI Condition\\AI Familiarity Model\\b/SE}" "\shortstack{Switching in AI Condition\\AI Knowledge Model\\b/SE}" "\shortstack{Switching in AI Condition\\AI Experience Model\\b/SE}" "\shortstack{Switching in AI Condition\\AI Background Model\\b/SE}") eqlabel(none)


* Figure 4

estimates clear

*/ AI Familiarity */

logit switch qpolitical level total_practice_correct age female educ treatment_high c.overallai_familiarity##c.overallai_familiarity normalized_overall_aibeliefs2 [pweight=weight] if treatment_ai==1, cluster(caseid)

eststo m1: margins, at( (means) _all overallai_familiarity=(0(.1)1)) post

coefplot m1, vertical recast(line) lcolor("240 91 67") lwidth(*2) ciopts(fcolor("254 172 129") fintensity(50) recast(rarea) lpatt(dash) lcolor(none)) xtitle(" " "AI Familiarity Index Squared", size(medsmall)) ytitle("Predicted Probability of Switching (AI Treatment)" " ", size(medsmall)) xlabel(1 "0" 2 ".1" 3 ".2" 4 ".3" 5 ".4" 6 ".5" 7 ".6" 8 ".7" 9 ".8" 10 ".9" 11 "1", grid) title("AI Familiarity")

graph save "aifamiliaritypredictedprobabilities.gph", replace
graph export "aifamiliaritypredictedprobabilities.tif", replace as(tif)

*/ AI Knowledge */

logit switch qpolitical level total_practice_correct age female educ treatment_high c.overallai_knowledge2##cc.overallai_knowledge2 normalized_overall_aibeliefs2 [pweight=weight] if treatment_ai==1, cluster(caseid)

eststo m2: margins, at( (means) _all overallai_knowledge2=(0(.1)1)) post

coefplot m2, vertical recast(line) lcolor("240 91 67") lwidth(*2) ciopts(fcolor("254 172 129") fintensity(50) recast(rarea) lpatt(dash) lcolor(none)) xtitle(" " "AI Knowledge Index Squared", size(medsmall)) ytitle("Predicted Probability of Switching (AI Treatment)" " ", size(medsmall)) xlabel(1 "0" 2 ".1" 3 ".2" 4 ".3" 5 ".4" 6 ".5" 7 ".6" 8 ".7" 9 ".8" 10 ".9" 11 "1", grid) title("AI Knowledge")

graph save "aiknowledgepredictedprobabilities.gph", replace
graph export "aiknowledgepredictedprobabilities.tif", replace as(tif)

*/ AI Experience */

logit switch qpolitical level total_practice_correct age female educ treatment_high c.overallai_experience2##cc.overallai_experience2 normalized_overall_aibeliefs2 [pweight=weight] if treatment_ai==1, cluster(caseid)

eststo m3: margins, at( (means) _all overallai_experience2=(0(.1)1)) post

coefplot m3, vertical recast(line) lcolor("240 91 67") lwidth(*2) ciopts(fcolor("254 172 129") fintensity(50) recast(rarea) lpatt(dash) lcolor(none)) xtitle(" " "AI Experience Index Squared", size(medsmall)) ytitle("Predicted Probability of Switching (AI Treatment)" " ", size(medsmall)) xlabel(1 "0" 2 ".1" 3 ".2" 4 ".3" 5 ".4" 6 ".5" 7 ".6" 8 ".7" 9 ".8" 10 ".9" 11 "1", grid) title("AI Experience")

graph save "aiexperiencepredictedprobabilities.gph", replace
graph export "aiexperiencepredictedprobabilities.tif", replace as(tif)

*/ AI Background */

logit switch qpolitical level total_practice_correct age female educ treatment_highconfidence c.aibackground##c.aibackground normalized_overall_aibeliefs2 [pweight=weight] if treatment_ai==1, cluster(caseid)

eststo m4: margins, at( (means) _all aibackground=(0(.1)1)) post

coefplot m4, vertical recast(line) lcolor("116 143 70") lwidth(*2) ciopts(fcolor("206 209 175") fintensity(50) recast(rarea) lpatt(dash) lcolor(none)) xtitle(" " "AI Background Index Squared", size(medsmall)) ytitle("Predicted Probability of Switching (AI Treatment)" " ", size(medsmall)) xlabel(1 "0" 2 ".1" 3 ".2" 4 ".3" 5 ".4" 6 ".5" 7 ".6" 8 ".7" 9 ".8" 10 ".9" 11 "1", grid) title("AI Background Index")

graph save "aibackgroundpredictedprobabilities.gph", replace
graph export "aibackgroundpredictedprobabilities.tif", replace as(tif)

* Robustness Regression Table in Appendix

estimates clear

* Country Variables for Models 4-7

*AI Familiarity Squared
eststo m1: logit switch qpolitical level total_practice_correct age female educ treatment_highconfidence overallai_familiarity aifamiliaritysquared normalized_overall_aibeliefs2 russia china uk australia japan skorea france sweden [pweight=weight] if treatment_ai==1, cluster(caseid)

* AI Knowledge Squared
eststo m2: logit switch qpolitical level total_practice_correct age female educ treatment_high overallai_knowledge2 overallai_knowledge2squared normalized_overall_aibeliefs2 russia china uk australia japan skorea france sweden [pweight=weight] if treatment_ai==1, cluster(caseid)

* AI Experience Squared
eststo m3: logit switch qpolitical level total_practice_correct age female educ treatment_high overallai_experience2 overallai_experience2squared normalized_overall_aibeliefs2 russia china uk australia japan skorea france sweden [pweight=weight] if treatment_ai==1, cluster(caseid)

*AI Background Squared
eststo m4: logit switch qpolitical level total_practice_correct age female educ treatment_highconfidence aibackground aibackgroundsquared normalized_overall_aibeliefs2 russia china uk australia japan skorea france sweden[pweight=weight] if treatment_ai==1, cluster(caseid)

* Regression + Country Variables for Models 4-7

*AI Familiarity Squared
eststo m5: regress switch qpolitical level total_practice_correct age female educ treatment_highconfidence overallai_familiarity aifamiliaritysquared normalized_overall_aibeliefs2 russia china uk australia japan skorea france sweden [pweight=weight] if treatment_ai==1, cluster(caseid)

* AI Knowledge Squared
eststo m6: regress switch qpolitical level total_practice_correct age female educ treatment_high overallai_knowledge2 overallai_knowledge2squared normalized_overall_aibeliefs2 russia china uk australia japan skorea france sweden [pweight=weight] if treatment_ai==1, cluster(caseid)

* AI Experience Squared
eststo m7: regress switch qpolitical level total_practice_correct age female educ treatment_high overallai_experience2 overallai_experience2squared normalized_overall_aibeliefs2 russia china uk australia japan skorea france sweden [pweight=weight] if treatment_ai==1, cluster(caseid)

*AI Background Squared
eststo m8: regress switch qpolitical level total_practice_correct age female educ treatment_highconfidence aibackground aibackgroundsquared normalized_overall_aibeliefs2 russia china uk australia japan skorea france sweden[pweight=weight] if treatment_ai==1, cluster(caseid)

esttab m1 m2 m3 m4 m5 m6 m7 m8 using TableAppendix.tex, replace f t(3) scalars("ll Log Likelihood" F) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 r2 b(3) star(* 0.10 ** 0.05 *** 0.01) nobaselevels order(qpolitical level total_practice_correct age female educ treatment_ai treatment_highconfidence overallai_familiarity aifamiliaritysquared overallai_knowledge2 overallai_knowledge2squared overallai_experience2 overallai_experience2squared aibackground aibackgroundsquared normalized_overall_aibeliefs2) drop(treatment_ai russia china uk australia japan skorea france sweden) mtitles("\shortstack{AI Familiarity\\Country Vars\\b/SE}" "\shortstack{AI Knowledge\\Country Vars\\b/SE}" "\shortstack{AI Experience\\Country Vars\\b/SE}" "\shortstack{AI Background\\Country Vars\\b/SE}" "\shortstack{AI Familiarity\\OLS\\b/SE}" "\shortstack{AI Knowledge\\OLS\\b/SE}" "\shortstack{AI Experience\\OLS\\b/SE}" "\shortstack{AI Background\\OLS\\b/SE}") eqlabel(none)

estimates clear

* Robustness Regression Table #2 in Appendix (no political variable so Russia included)

* Country Variables for Models 4-7

*AI Familiarity Squared
eststo m1: logit switch level total_practice_correct age female educ treatment_highconfidence overallai_familiarity aifamiliaritysquared normalized_overall_aibeliefs2 russia china uk australia japan skorea france sweden [pweight=weight] if treatment_ai==1, cluster(caseid)

* AI Knowledge Squared
eststo m2: logit switch level total_practice_correct age female educ treatment_high overallai_knowledge2 overallai_knowledge2squared normalized_overall_aibeliefs2 russia china uk australia japan skorea france sweden [pweight=weight] if treatment_ai==1, cluster(caseid)

* AI Experience Squared
eststo m3: logit switch level total_practice_correct age female educ treatment_high overallai_experience2 overallai_experience2squared normalized_overall_aibeliefs2 russia china uk australia japan skorea france sweden [pweight=weight] if treatment_ai==1, cluster(caseid)

*AI Background Squared
eststo m4: logit switch level total_practice_correct age female educ treatment_highconfidence aibackground aibackgroundsquared normalized_overall_aibeliefs2 russia china uk australia japan skorea france sweden[pweight=weight] if treatment_ai==1, cluster(caseid)

* Regression + Country Variables for Models 4-7

*AI Familiarity Squared
eststo m5: regress switch level total_practice_correct age female educ treatment_highconfidence overallai_familiarity aifamiliaritysquared normalized_overall_aibeliefs2 russia china uk australia japan skorea france sweden [pweight=weight] if treatment_ai==1, cluster(caseid)

* AI Knowledge Squared
eststo m6: regress switch level total_practice_correct age female educ treatment_high overallai_knowledge2 overallai_knowledge2squared normalized_overall_aibeliefs2 russia china uk australia japan skorea france sweden [pweight=weight] if treatment_ai==1, cluster(caseid)

* AI Experience Squared
eststo m7: regress switch level total_practice_correct age female educ treatment_high overallai_experience2 overallai_experience2squared normalized_overall_aibeliefs2 russia china uk australia japan skorea france sweden [pweight=weight] if treatment_ai==1, cluster(caseid)

*AI Background Squared
eststo m8: regress switch level total_practice_correct age female educ treatment_highconfidence aibackground aibackgroundsquared normalized_overall_aibeliefs2 russia china uk australia japan skorea france sweden[pweight=weight] if treatment_ai==1, cluster(caseid)

esttab m1 m2 m3 m4 m5 m6 m7 m8 using TableAppendix2.tex, replace f t(3) scalars("ll Log Likelihood" F) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 r2 b(3) star(* 0.10 ** 0.05 *** 0.01) nobaselevels order(level total_practice_correct age female educ treatment_ai treatment_highconfidence overallai_familiarity aifamiliaritysquared overallai_knowledge2 overallai_knowledge2squared overallai_experience2 overallai_experience2squared aibackground aibackgroundsquared normalized_overall_aibeliefs2) drop(treatment_ai russia china uk australia japan skorea france sweden) mtitles("\shortstack{AI Familiarity\\Country Vars\\b/SE}" "\shortstack{AI Knowledge\\Country Vars\\b/SE}" "\shortstack{AI Experience\\Country Vars\\b/SE}" "\shortstack{AI Background\\Country Vars\\b/SE}" "\shortstack{AI Familiarity\\OLS\\b/SE}" "\shortstack{AI Knowledge\\OLS\\b/SE}" "\shortstack{AI Experience\\OLS\\b/SE}" "\shortstack{AI Background\\OLS\\b/SE}") eqlabel(none)

log close

clear
exit